FROM node:12.14-alpine AS build

WORKDIR /src
COPY . .
#ENV HOME=/tmp
ARG BUILD_TYPE
RUN yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ \
    && yarn config set registry https://registry.npm.taobao.org \
    && yarn install --verbose \
    && yarn build \
    && yarn install --production --ignore-scripts --prefer-offline \
    && yarn cache clean --force

FROM node:12.14-alpine

WORKDIR /app

RUN yarn config set registry https://registry.npm.taobao.org \
    && yarn global add supervisor
COPY --chown=node:node --from=build /src/*.pem ./
COPY --chown=node:node --from=build /src/dist dist/
COPY --chown=node:node --from=build /src/node_modules node_modules/

EXPOSE 8081
USER node

ENTRYPOINT [ "supervisor", "--harmony", "-w", "dist", "-e", "node,js,json", "dist/index.js" ]
